package br.ufrj.dcc.smarthotel;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

/***
 * Activity que contem o menu inicial da aplicacao
 * @author Diego Xavier
 * @author Patricia Zudio
 */
public class MainMenuActivity extends Activity implements OnItemClickListener {
	
	//Lista de itens do menu
    public JSONObject[] menuItems;
    
    /***
     * Metodo chamado na criacao da Activity
     * @param savedInstanceState - Parametros para a inicializacao da Activity
     */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	try {
			JSONObject[] localMenuItems = {
					new JSONObject("{menuID:" + Constants.TOUR + ", 		image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.SERVICES + ", 	image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.EVENTS + ", 		image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.GUESTBOOK + ", 	image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.SALES + ", 		image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.FEEDBACK + ", 	image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.FAQ + ", 			image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.CHECKOUT + ", 	image:" + R.drawable.diego + "}"),
					new JSONObject("{menuID:" + Constants.FOODELICIUS + ", 	image:" + R.drawable.diego + "}")
			};
			
			this.menuItems = localMenuItems;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
    	//Chama o OnCreate da Classe Activity
        super.onCreate(savedInstanceState);
        //Seta o Layout da Activity
        setContentView(R.layout.dashboard);
        
//        //Pega a Grid que ficara com o menu principal
//        GridView gridView = (GridView) findViewById(R.id.gridMainMenu);
//        //Seta o Adaptador que contem o template de apresentacao das imagens do menu
//        gridView.setAdapter(new ImageAdapterMenu(this, this.menuItems));
//    	//Seta o Listener para o evento de click do menu
//        gridView.setOnItemClickListener(this);
    }
    
    /***
     * Metodo que trata o click de um item de menu
     * @param parent - Adaptador da GridView que contem o template do menu
     * @param v - View do item do menu que foi clicado
     * @param position - Posicao do item no menu
     * @param id - Id do item
     */
    public void onItemClick(AdapterView parent, View v, int position, long id) 
    {   
    	//Cria um novo intent para ir para a proxima tela
    	Intent it = null;
    	
    	//Verifica qual o item de menu que foi selecionado
    	try {
    		int menuID = this.menuItems[position].getInt("menuID");
    		switch (menuID){
    			case Constants.TOUR:
    				it = new Intent(this, TourMenuActivity.class);
    				break;
    			default:
    				it = new Intent(this, TourMenuActivity.class);
    				break;
    		}
    		//Inicia a activity selecionada
    		startActivity(it);
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	
    }
    
}
